package org.example.zuoye.api;

import jakarta.servlet.http.HttpServletResponse;
import org.example.zuoye.entity.Doctor;
import org.example.zuoye.entity.Result;
import org.example.zuoye.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xinchen
 * @Date: 2024/08/10/ 16:04
 * @Description 控制层管理员
 */
@RestController
@RequestMapping(value = "/api/v1/doctor")
public class DoctorApi {

    @Autowired
    private DoctorService doctorService;

    /**
     * 多条件分页查询
     */
    @GetMapping
    public Result search(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,
                         Doctor doctor){
        return Result.success(doctorService.search(page, limit, doctor));
    }
    /**
     * 删除 remove
     */
    @DeleteMapping
    public Result remove(@RequestBody Integer[] ids){
        try {
            doctorService.remove(ids);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
    /**
     * add
     */
    @PostMapping
    public Result add(@RequestBody Doctor doctor){
        try {
            doctorService.add(doctor);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    // edit
    @PutMapping
    public Result edit(@RequestBody Doctor doctor){
        try {
            doctorService.update(doctor);
            return Result.success();
        }
        catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    /**
     * 导出操作
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        doctorService.export(response);
    }


}



